package com.dd.algorithm;

public class BubleSort {
	
    public static int[] sort(int[] a){
  
    	
    	for(int i=0;i<a.length;i++){
    	  	boolean exchange = false;
    		int temp = 0;
    		for(int j =0;j<a.length-i-1;j++){
    			if(a[j]>a[j+1]){
    				temp = a[j];
    				a[j] = a[j+1];
    				a[j+1] = temp;
    				exchange = true;
    			}
    		}
    		
    		if(exchange==false) break;
    	    
    		System.out.println("The round "+(i+1)+" Sort:");
    		for(int k = 0;k<a.length;k++){
    			System.out.print(a[k]+" ");
    		}
    		System.out.println();
    	}
    	
    	return a;
    }
    
    public static void main(String[] args){
    	
    	int[] arr = {4,7,8,9,3,2};
    	sort(arr);
    	for(int i =0;i<arr.length;i++){
    		//System.out.print(arr[i]+" ");
    	}
  
    	
    }
}
